package com.yf.bytecode;

public class PolymorphismTest {
    public static void main(String[] args) {
        Ancestor obj = new Descendant();
        System.out.println(obj.x);
    }
}

class Ancestor {
    int x = 10;
    public Ancestor() {
        this.print();
        x = 20;
    }

    public void print() {
        System.out.println("Ancestor.x = " + x);
    }
}

class Descendant extends Ancestor {
    int x  = 30;
    public Descendant() {
        this.print();
        x = 40;
    }

    public void print() {
        System.out.println("Descendant.x = " + x);
    }
}
